package cn.zzp.homework.xhr;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @ClassName Producer
 * @Description
 * @Author 祝志鹏
 * @Date 2022/8/17 22:14
 */
public class Producer {

    public static void main(String[] args) throws Exception {

        DefaultMQProducer producer = new DefaultMQProducer("xhr_product_group");

        producer.setNamesrvAddr("localhost:9876");

        producer.start();

        Message message = new Message("xhr", "hello", "异步消息发送测试".getBytes(StandardCharsets.UTF_8));

        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("异步消息消费成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("异步消息消费失败");
            }
        });

    }
}
